<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单据编号" prop="code">
        <el-input
            v-model="queryParams.code"
            placeholder="请输入单据编号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="源单编号" prop="sourceCode">
        <el-input
            v-model="queryParams.sourceCode"
            placeholder="请输入源单编号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="单据日期" prop="docTime">
        <el-date-picker clearable
                        v-model="queryParams.docTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择单据日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="供应商id" prop="supId">
        <el-input
            v-model="queryParams.supId"
            placeholder="请输入供应商id"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务员id" prop="businessUserId">
        <el-input
            v-model="queryParams.businessUserId"
            placeholder="请输入业务员id"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['finance:buyPayReq:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['finance:buyPayReq:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['finance:buyPayReq:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['finance:buyPayReq:export']"
        >导出
        </el-button>

      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="buyPayReqList" border  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
<!--      <el-table-column label="主键" align="center" prop="id"/>-->
      <el-table-column label="单据编号" align="center" prop="code" width="200">
        <template slot-scope="scope">
          <el-button type="text"  @click="info(scope.row)">{{scope.row.code}}</el-button>
        </template>
      </el-table-column>
<!--      <el-table-column label="源单号" align="center" prop="sourceCode" width="200"/>-->
      <el-table-column label="单据类型" align="center" prop="codeTypeName" width="200"/>
      <el-table-column label="单据日期" align="center" prop="docTime" width="130">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.docTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="供应商" align="center" prop="supName" width="150"/>
      <el-table-column label="客户" align="center" prop="cusName" width="150"/>
      <el-table-column label="单据阶段" align="center" prop="docStage">
        <template slot-scope="scope">
          <span v-if="scope.row.docStage == 0">编制完</span>
          <span v-if="scope.row.docStage == 1">执行中</span>
          <span v-if="scope.row.docStage == 2">执行完</span>
        </template>
      </el-table-column>
      <el-table-column label="审批结果" align="center" prop="approvalResult">
        <template slot-scope="scope">
<!--          <span v-if="scope.row.approvalResult == 0 || scope.row.approvalResult == undefined || scope.row.approvalResult == null">待审核</span>-->
<!--          <span v-else-if="scope.row.approvalResult == 1">审核通过</span>-->
<!--          <span v-else-if="scope.row.approvalResult == 2">审核不通过</span>-->
          <el-tag type="success"  v-if="scope.row.approvalResult == 1">审核通过</el-tag>
          <el-tag type="danger" v-if="scope.row.approvalResult == 2">审核不通过</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否生效" align="center" prop="isEffect">
        <template slot-scope="scope">
          <span v-if="scope.row.isEffect == 0 || scope.row.isEffect == undefined || scope.row.isEffect == null">否</span>
          <span v-else>是</span>
        </template>
      </el-table-column>
      <el-table-column label="是否关闭" align="center" prop="isClose">
        <template slot-scope="scope">
          <span v-if="scope.row.isClose == 0 || scope.row.isClose == undefined || scope.row.isClose == null">否</span>
          <span v-else>是</span>
        </template>
      </el-table-column>
      <el-table-column label="是否作废" align="center" prop="isCancel">
        <template slot-scope="scope">
          <span v-if="scope.row.isCancel == 0 || scope.row.isCancel == undefined || scope.row.isCancel == null">否</span>
          <span v-else>是</span>
        </template>
      </el-table-column>

      <el-table-column label="申请金额" align="center" prop="requestAmount"/>
      <el-table-column label="已付金额" align="center" prop="paidAmount"/>

<!--      <el-table-column label="源单编号" align="center" prop="sourceCode"/>-->
      <el-table-column label="制单人" align="center" prop="docMakeUserName"/>

      <el-table-column label="业务员" align="center" prop="businessUserName"/>

      <el-table-column label="审批意见" align="center" prop="approvalRemark"/>
      <el-table-column label="审批人" align="center" prop="approvalUserName"/>

      <el-table-column  fixed="right" width="200" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['finance:buyPayReq:edit']"
              :disabled="scope.row.approvalResult!=0"
          >修改
          </el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['finance:buyPayReq:remove']"
          >删除
          </el-button>
          <el-button  size="mini"
                      type="text"
                      icon="el-icon-thumb"
                      @click="approval(scope.row)"
                      :disabled="!(scope.row.approvalResult===0)">
            审 核
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改采购付款申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1300px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" inline label-width="80px">
        <el-form-item label="单据编号" prop="code">
          <el-input v-model="form.code" placeholder="请输入单据编号" readonly/>
        </el-form-item>

<!--        <el-form-item label="供应商" prop="supId">-->
<!--          &lt;!&ndash;          <el-select v-model="form.supId" placeholder="请选择"  :disabled="bjdGoodList.length>0">&ndash;&gt;-->
<!--          <el-select v-model="form.supId" placeholder="请选择" @change="supSelectChanged" :disabled="cgrkList.length >0 || isInfo" >-->
<!--            <el-option-->
<!--                v-for="item in supplierList"-->
<!--                :key="item.id"-->
<!--                :label="item.supName"-->
<!--                :value="item.id">-->
<!--            </el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->


        <el-form-item label="单据日期" prop="docTime">
          <el-date-picker clearable
                          v-model="form.docTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择单据日期"
          :readonly="isInfo">
          </el-date-picker>
        </el-form-item>
        <template>
          <el-button type="text" v-if="isFormMore" @click="isFormMore = false">收起</el-button>
          <el-button type="text" v-else @click="isFormMore = true">更多</el-button>
        </template>
        <div v-show="isFormMore">
          <el-form-item label="申请金额" prop="requestAmount">
            <el-input v-model="form.requestAmount" placeholder="请输入申请金额" :readonly="isInfo"/>
          </el-form-item>
          <el-form-item label="已付金额" prop="paidAmount">
            <el-input v-model="form.paidAmount" placeholder="请输入已付金额" readonly/>
          </el-form-item>

          <el-form-item label="单据阶段" prop="docStage">
<!--            <el-input v-model="form.docStage" placeholder="请输入单据阶段" readonly/>-->
            <el-select v-model="form.docStage" disabled>
              <el-option :value="0" label="编制完">编制完</el-option>
              <el-option :value="1" label="执行中">执行中</el-option>
              <el-option :value="2" label="执行完">执行完</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="制单人" prop="docMakeUserName">
            <el-input v-model="form.docMakeUserName" placeholder="制单人" readonly/>
          </el-form-item>

          <el-form-item label="业务员" prop="businessUserName">
            <el-input v-model="form.businessUserName" placeholder="业务员" readonly/>
          </el-form-item>

          <el-form-item label="审批人" prop="approvalUserId">
            <el-input v-model="form.approvalUserName" placeholder="审批人" readonly/>
          </el-form-item>
          <el-form-item label="是否生效" prop="isEffect">
<!--            <el-input v-model="form.isEffect" placeholder="请输入是否生效" readonly/>-->
            <el-select v-model="form.isEffect" disabled>
              <el-option :value="0" label="否">否</el-option>
              <el-option :value="1" label="是">是</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否关闭" prop="isClose" >
            <el-select v-model="form.isClose" disabled>
              <el-option :value="0" label="否">否</el-option>
              <el-option :value="1" label="是">是</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否作废" prop="isCancel" >
<!--            <el-input v-model="form.isCancel" placeholder="请输入是否作废" readonly/>-->
            <el-select v-model="form.isCancel" disabled>
              <el-option :value="0" label="否">否</el-option>
              <el-option :value="1" label="是">是</el-option>
            </el-select>
          </el-form-item>
        </div>


      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="采购入库单" name="first">
          <!--          <el-button plain type="primary" icon="el-icon-plus" @click="addBjd" :disabled="!(form.supId>0)">比价单</el-button>-->
          <el-form-item label="供应商" prop="supId">
            <!--          <el-select v-model="form.supId" placeholder="请选择"  :disabled="bjdGoodList.length>0">-->
            <el-select v-model="form.supId" placeholder="请选择" @change="supSelectChanged" :disabled="cgrkList.length >0 || isInfo" >
              <el-option
                v-for="item in supplierList"
                :key="item.id"
                :label="item.supName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-button plain type="primary" icon="el-icon-plus" @click="addCgrk" :disabled="!(form.supId > 0) || isInfo ">
            采购入库单
          </el-button>
          <el-button type="primary" icon="el-icon-minus" @click="removeCgrk" :disabled="isInfo">移除
          </el-button>
          <el-table :data="cgrkList"
                    border
                    @selection-change="handleSelectionChangeCgrk"
          >
            <el-table-column
                type="selection"
                width="55">
            </el-table-column>
            <el-table-column prop="stockInCode" label="单据编号"/>
            <el-table-column prop="orderCode" label="源单编号"/>
            <el-table-column prop="cost" label="结算金额"/>
            <el-table-column prop="paidAmount" label="已结算金额"/>
          </el-table>

        </el-tab-pane>
        <el-tab-pane label="销售退货入库单" name="third">
          <el-form-item label="客户" prop="cusId">
            <el-select v-model="form.cusId" placeholder="请选择" @change="cusSelectChanged" :disabled="xsthrkList.length >0 || isInfo" >
              <el-option
                v-for="item in customerList"
                :key="item.id"
                :label="item.cusName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-button plain type="primary" icon="el-icon-plus" @click="addXsthrk" :disabled="!(form.cusId > 0) || isInfo ">
            销售退货入库单
          </el-button>
          <el-button type="primary" icon="el-icon-minus" @click="removeXsthrk" :disabled="isInfo">移除
          </el-button>
          <el-table :data="xsthrkList"
                    border
                    @selection-change="handleSelectionChangeXsthrk"
          >
            <el-table-column
              type="selection"
              width="55">
            </el-table-column>
            <el-table-column prop="stockInCode" label="单据编号"/>
            <el-table-column prop="orderCode" label="源单编号"/>
            <el-table-column prop="cost" label="结算金额"/>
            <el-table-column prop="paidAmount" label="已结算金额"/>
          </el-table>

        </el-tab-pane>
        <el-tab-pane label="明细" name="second">
          <!--          <el-button type="primary" @click="addGoods">添加</el-button>-->
          <!--          <el-button type="primary" icon="el-icon-minus" @click="removeOrderGoods"-->
          <!--                     v-show="selectOrderGoodList.length>0">移除-->
          <!--          </el-button>-->
          <el-table :data="cgrkDetailsList"
                    border
                    @selection-change="handleSelectionChangeCgrk"
          >
            <el-table-column
                type="selection"
                width="55">
            </el-table-column>
<!--            <el-table-column prop="stockInCode" label="单据编号"/>-->
            <el-table-column prop="sourceCode" label="源单编号"/>
<!--            <el-table-column prop="cost" label="结算金额"/>-->
<!--            <el-table-column prop="paidAmount" label="已结算金额"/>-->
            <el-table-column prop="requestAmount" label="申请金额">
              <template slot-scope="scope">
<!--                <MyNumberInput-->
                <MyNumberInput :point="2" :max="scope.row.cost-scope.row.paidAmount" placeholder="请输入金额"
                               v-model.number="scope.row.requestAmount" :disabled="isInfo"></MyNumberInput>
              </template>
            </el-table-column>

            <el-table-column prop="paidAmount" label="已付金额" />
          </el-table>

        </el-tab-pane>
      </el-tabs>
      <div class="demo-input-suffix" v-show="isApproval">
        审核意见：
        <el-input
            v-model="form.approvalRemark" style="width: 300px">
        </el-input>
        审核结果：
        <el-select v-model="form.approvalResult">
          <el-option
              v-for="item in [{id:0,value:0,name:'请选择'},{id:1,value:1,name:'通过'},{id:2,value:2,name:'不通过'}]"
              :key="item.id"
              :label="item.name"
              :value="item.value"/>
        </el-select>
      </div>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-show="!isApproval">确 定</el-button>
        <el-button type="primary" @click="submitFormApproval" v-show="isApproval">审核</el-button>

        <el-button @click="cancel">取 消</el-button>
      </div>

    </el-dialog>

    <el-dialog
        title="选择采购入库单"
        :visible.sync="selectCgrkDialogVisible"
        width="1000px"
        :close-on-click-modal="false"
        :close-on-press-escape="false">
      <SelectCgrk ref="selectCgrkComponent" :supId="form.supId"/>
      <span slot="footer" class="dialog-footer">
     <el-button @click="cancelSelectCgrk">取 消</el-button>
    <el-button type="primary" @click="sureSelectCgrk">确 定</el-button>
  </span>
    </el-dialog>

    <el-dialog
      title="选择销售退货入库单"
      :visible.sync="selectXsthrkDialogVisible"
      width="1000px"
      :close-on-click-modal="false"
      :close-on-press-escape="false">
      <SelectXsthrk ref="selectXsthrkComponent" :cusId="form.cusId"/>
      <span slot="footer" class="dialog-footer">
     <el-button @click="cancelSelectXsthrk">取 消</el-button>
    <el-button type="primary" @click="sureSelectXsthrk">确 定</el-button>
  </span>
    </el-dialog>

  </div>
</template>

<script>
import {
  listBuyPayReq,
  getBuyPayReq,
  delBuyPayReq,
  addBuyPayReq,
  updateBuyPayReq,
  addBuyPayReqPlus,
  approvalBuyPayReq
} from "@/api/finance/buyPayReq";
import {listSupplies} from "@/api/basedata/supplies";
import SelectBjd from "@/views/caigou/buyOrder/SelectBjd.vue";
import SelectCgrk from "@/views/finance/buyPayReq/SelectCgrk.vue";
import SelectXsthrk from "@/views/finance/buyPayReq/SelectXsthrk.vue";
import MyNumberInput from "@/views/caigou/gysbj/MyNumberInput.vue";
import {listCustomer} from "@/api/basedata/customer";

export default {
  name: "BuyPayReq",
  components: {MyNumberInput, SelectCgrk, SelectBjd,SelectXsthrk},
  data() {
    return {
      selectXsthrkList:[],
      xsthrkList:[],
      customerList:[],
      isInfo:false,
      isApproval:false,
      selectCgrkList:[],
      cgrkDetailsList:[],
      cgrkList:[],
      selectCgrkDialogVisible: false,
      selectXsthrkDialogVisible: false,
      activeName: 'second',
      isFormMore: false,
      //供应商数组
      supplierList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购付款申请表格数据
      buyPayReqList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        sourceCode: null,
        requestAmount: null,
        paidAmount: null,
        docTime: null,
        docStage: null,
        docMakeUserId: null,
        supId: null,
        businessUserId: null,
        approvalResult: null,
        approvalRemark: null,
        approvalUserId: null,
        isEffect: null,
        isClose: null,
        isCancel: null,
        orderByColumn:'create_time',
        isAsc:'desc'
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        code: [
          {required: true, message: "单据编号不能为空", trigger: "blur"}
        ],
        docTime: [
          {required: true, message: "单据日期不能为空", trigger: "blur"}
        ],
        // supId: [
        //   {required: true, message: "供应商不能为空", trigger: "blur"}
        // ],
        // cusId:[
        //   {required: true, message: "客户不能为空", trigger: "blur"}
        // ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    info(row){
      this.isInfo = true;
      this.reset();
      const id = row.id || this.ids
      getBuyPayReq(id).then(response => {
        this.form = response.data;
        this.cgrkDetailsList = this.form.list;
        this.open = true;
        this.title = "查看采购付款申请";
      });
    },
    submitFormApproval(){
      if (this.form.approvalResult == null || this.form.approvalResult == undefined ||this.form.approvalResult == ''){
        this.$modal.msgWarning("选择审核结果")
        return
      }
      if (this.form.approvalResult == 1){
        this.form.isEffect = 1
        this.form.docStage = 1
      }else if (this.form.approvalResult == 2) {
        this.form.isEffect = 0
        this.form.docStage = 2
      }

      approvalBuyPayReq(this.form).then(res=>{
        this.$modal.msgSuccess("审核成功");
        this.open = false;
        this.getList();
      }
    )

    },
    approval(row){
      this.open = true;
      this.reset();
      const id = row.id || this.ids
      getBuyPayReq(id).then(response => {
        this.form = response.data;
        this.cgrkDetailsList = this.form.list;
        this.open = true;
        this.title = "审核采购付款申请";
      });
      this.isApproval = true;

    },
    removeCgrk(){
      let filterArr = [];
      let filterArr2 = [];
      if (this.selectCgrkList.length>0){
        this.selectCgrkList.forEach(a=>{
          filterArr = this.cgrkList.filter(obj=>obj.stockInCode !== a.stockInCode);
          filterArr2 = this.cgrkDetailsList.filter(obj=>obj.stockInCode !== a.stockInCode);
          this.cgrkList = filterArr;
          this.cgrkDetailsList = filterArr2;
        })
      }
    },

    removeXsthrk(){
      // let filterArr = [];
      // let filterArr2 = [];
      // if (this.selectCgrkList.length>0){
      //   this.selectCgrkList.forEach(a=>{
      //     filterArr = this.cgrkList.filter(obj=>obj.stockInCode !== a.stockInCode);
      //     filterArr2 = this.cgrkDetailsList.filter(obj=>obj.stockInCode !== a.stockInCode);
      //     this.cgrkList = filterArr;
      //     this.cgrkDetailsList = filterArr2;
      //   })
      // }
    },
    handleSelectionChangeCgrk(selection){
      this.selectCgrkList = selection;
    },
    handleSelectionChangeXsthrk(selection){
      this.selectXsthrkList = selection;
    },
    sureSelectCgrk() {
      let cgrkList = this.$refs.selectCgrkComponent.returnSelectCgrkList();
      console.log('cgrkList',cgrkList)
      this.cgrkList = cgrkList;
      this.cgrkDetailsList = [];
      cgrkList.forEach(item=>{
        this.cgrkDetailsList.push({...item,requestAmount: item.cost-item.paidAmount,sourceCode:item.stockInCode})
      })
      this.selectCgrkDialogVisible = false;
    },
    sureSelectXsthrk(){
      let cgrkList = this.$refs.selectXsthrkComponent.returnSelectCgrkList();
      console.log('cgrkList',cgrkList)
      this.xsthrkList = cgrkList;
      this.cgrkDetailsList = [];
      cgrkList.forEach(item=>{
        this.cgrkDetailsList.push({...item,requestAmount: item.cost-item.paidAmount,sourceCode:item.stockInCode})
      })
      this.selectXsthrkDialogVisible = false;
    },
    cancelSelectCgrk() {
      this.selectCgrkDialogVisible = false;
    },
    cancelSelectXsthrk() {
      this.selectXsthrkDialogVisible = false;
    },
    addCgrk() {
      this.selectCgrkDialogVisible = true;
      this.$refs.selectCgrkComponent.setSupId(this.form.supId)
    },
    addXsthrk() {
      this.selectXsthrkDialogVisible = true;
      this.$refs.selectXsthrkComponent.setCusId(this.form.cusId)
    },
    handleClick(tab, event) {
      console.log(tab, event);
      console.log(tab.index)
      if (tab.index == 0){
        this.form.cusId = null
        this.xsthrkList = [];

      }else if (tab.index == 1){
        this.form.supId = null
        this.cgrkList = [];

      }else if (tab.index == 2){
        if (this.cgrkList.length == 0 && this.xsthrkList.length == 0){
          this.cgrkDetailsList = []
        }
      }



    },
    // 新增初始化数据
    initBaseData() {
      //获取所有供应商
      listSupplies().then(res => {
        this.supplierList = res.rows
      })
      //获取所有客户
      listCustomer({}).then(res =>{
        this.customerList = res.rows
      })
      this.isFormMore = false;
      this.isApproval = false;
      this.cgrkDetailsList = [];
      this.cgrkList = [];
      this.xsthrkList = [];
    },
    supSelectChanged() {

    },
    cusSelectChanged() {

    },
    /** 查询采购付款申请列表 */
    getList() {
      this.loading = true;
      listBuyPayReq(this.queryParams).then(response => {
        this.buyPayReqList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.isInfo = false;
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: 'FKSQ-' + Date.now(),
        sourceCode: null,
        requestAmount: null,
        paidAmount: null,
        docTime: null,
        docStage: null,
        docMakeUserId: null,
        supId: null,
        businessUserId: null,
        approvalResult: null,
        approvalRemark: null,
        approvalUserId: null,
        isEffect: null,
        isClose: null,
        isCancel: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        list:[],
        cusId:null,
      };
      this.resetForm("form");
      this.initBaseData();

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加采购付款申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBuyPayReq(id).then(response => {
        this.form = response.data;
        this.cgrkDetailsList = this.form.list;
        this.open = true;
        this.title = "修改采购付款申请";
      });
    },
    /** 提交按钮 */
    submitForm() {
      if (this.isInfo){
        this.isInfo = false;
        return;
      }
      if (this.cgrkDetailsList.length == 0){
        this.$modal.msgWarning("明细不能为空");
        return;
      }

      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.list = this.cgrkDetailsList;

          if (this.form.id != null) {
            updateBuyPayReq(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBuyPayReq(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除采购付款申请编号为"' + ids + '"的数据项？').then(function () {
        return delBuyPayReq(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('finance/buyPayReq/export', {
        ...this.queryParams
      }, `buyPayReq_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
